﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace NC.Infrastructure.Extension
{
    public class PagerExtension
    {
        /// <summary>
        /// 用正则表达式匹配Pager模板
        /// </summary>
        /// <param name="pageString"></param>
        /// <returns></returns>
        public static bool IsMathPager(string pageString)
        {
            Regex reg = new Regex(@"^((\w{0,15})+(=)+({)+(\d)+(}))$");
            return reg.IsMatch(pageString);
        }

        /// <summary>
        /// 提取Pager里面
        /// </summary>
        /// <param name="pageString"></param>
        /// <returns></returns>
        public static string MathPagerNum(string pageString)
        {
            if (IsMathPager(pageString))
                return string.Empty;
            Regex reg = new Regex(@"^((\w{0,15})+(=)+({)+(\d)+(}))$");
            var result = reg.Match(pageString).Groups;
            return result[result.Count - 2].Value;
        }

        /// <summary>
        /// 用正则表达式判断QueryString是否正确
        /// </summary>
        /// <param name="queryString"></param>
        /// <returns></returns>
        public static bool IsMatchQueryString(string queryString)
        {
            Regex reg = new Regex(@"^(\?((((\w{0,15})+(=)+(\d{0,15}|(\w{0,15})))\&){0,16}))$");
            return reg.IsMatch(queryString);
        }
    }
}
